<?

 class Controller_Catalog extends Controller_Base {

	private $infrastructure = null;

	function __construct($registry = null) {
		parent::__construct();

		Catalog::init();
		$this->config 			= Catalog::config(); 
		$this->infrastructure 	= Catalog::infrastructure(); 
	}	
	
	function index ($args) {
		$template = new Template();
		$template->setArgs(array(
			__content	=> 'catalog',
			rows 		=> ObjectsPeer::doSelect(new Criteria()),
		));
		return $template;
	}

	function apartments($args) {
		return $this->_types(1);
	}

	function villas($args) {
		return $this->_types(2);
	}

	function grounds($args) {
		return $this->_types(3);
	}
	
	function _types($type) {
		$template = new Template();	
		$c = new Criteria();
		$c->add(ObjectsPeer::TYPEID, $type);
		
		$cities = CitiesPeer::doSelect(new Criteria());
		
		$template->setArgs(array(
			__content	 => 'catalog',
			rows 		 => ObjectsPeer::doSelect($c),
		));
		
		return $template;
		
	}

	function city($args) {
		$template = new Template();
		$c = new Criteria();
				
		$c->add(CitiesPeer::CITYLINK, $args[0]);
		$city = CitiesPeer::doSelect($c);
		
		$template->setArgs(array(
			__content	 => 'catalog',
			rows 		 => count($city) ? $city[0]->getObjectss() : null,
		));

		return $template;
	}

	function show($args) {
		$template = new Template();
	
		$template->setArgs(array(
			item 		=> ObjectsPeer::retrieveByPK(intval($args[0])),
			__content	=> 'item'
		));
		
		return $template;
	}

}
